package com.googlecode.sampleproject.biz;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.googlecode.allinclusive.fw.database.dao.QueryDAO;
import com.googlecode.allinclusive.fw.valueobject.UserObject;
import com.googlecode.sampleproject.entity.UserEntity;

public class A1000WBizImpl implements A1000WBiz {

	@Autowired
	QueryDAO quertDAO;
	
	public UserObject login(UserEntity user) {
		 
		Map<String, Object> sqlParams = new HashMap<String, Object>();
		sqlParams.put("userId", user.getUserId());
		UserEntity userEntity = quertDAO.executeForObject("user.select", sqlParams, UserEntity.class);
		if (userEntity == null) {
			return null;
		}
		
		if (!StringUtils.equals(user.getPassword(), userEntity.getPassword())) {
			return null;
		}
		
		UserObject userObject = new UserObject();
		userObject.setUserId(userEntity.getUserId());
		return userObject;
	}
}
